﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebServiceRequester
{
    public partial class WebFormServiceRequester : System.Web.UI.Page
    {
        // Declare web service reference
        private ServiceNombrePremier.WebServiceNombrePremierSoapClient wsNbrPrem;

        protected void Page_Load(object sender, EventArgs e)
        {
            // Create instance of Nombre premier Service
            wsNbrPrem = new ServiceNombrePremier.WebServiceNombrePremierSoapClient();
        }

        protected void btn_get_Click(object sender, EventArgs e)
        {
            Int32 startInterval, endInterval;
            List<int> resultNbrPrem = new List<int>();

            if (Int32.TryParse(this.txt_startInterval.Text, out startInterval) && 
                Int32.TryParse(this.txt_endInterval.Text, out endInterval))
            {
                if (endInterval <= 39569)
                {
                    resultNbrPrem = wsNbrPrem.PremiersRange(startInterval, endInterval)
                                                .ToList<Int32>();
                }
            }

            DisplayResult(resultNbrPrem);
        }

        private void DisplayResult(List<int> resultNbrPrem)
        {
            // Display list of int in listBox
            lb_result.DataSource = resultNbrPrem;
            lb_result.DataBind();
        }

    }
}